Inside Macintosh: QuickTime

Previous | Chapter Top | Chapter Contents | Next

Text Media Handler Functions

This section describes the functions and structure associated with the text media handler, which allows you to display text in movies. You can use text media handlers to

A particular text sample has a default font, size, typeface, and color as well as a location (text box) within the track bounds to be drawn. The data format allows you to include style run information for the text. You can set flags to clip the display to the text box, inhibit automatic scaling of text as the track bounds are scaled, scroll the text, and specify if text is to be displayed at all.

The Movie Toolbox provides functions to help you add text samples to a track. You can use the TextMediaAddTextSample function to add text to a media. The TextMediaAddTESample function allows you to specify a TextEdit handle (which may have multiple style runs) to be added to a media. The TextMediaAddHiliteSample function allows you to indicate highlighting for text that has just been added with the TextMediaAddTextSample or TextMediaAddTESample function. For more information on styled text, style runs, and TextEdit, see Inside Macintosh: Text .

The format of the text data that is added to the media is a 16-bit length word followed by the text. The length word specifies the number of bytes in the text. Optionally, one or more atoms of additional data may follow. An atom is structured as a 32-bit length word followed by a 32-bit type followed by some data. The length word includes the size of the data as well as the length and type fields (in other words, the size of the data plus 8).

Text atom types include the style atom ( 'styl' ), the shrunken text box atom ( 'tbox' ), the highlighting atom ( 'hlit' ), the scroll delay atom ( 'dlay' ), and the highlight color atom ( 'hclr' ).

The format of the style atom is the same as TextEdit's StScrpRec data type. A StScrpRec data type is a short integer specifying the number of style runs followed by that number of ScrpSTElement data types, each specifying a different style run.

The shrunken text box atom is added when you set the dfShrinkTextBoxToFit display flag (in the TextMediaAddTextSample or TextMediaAddTESample function). Its format is simply the rectangle of the shrunken box (16 bytes total, including length and type).

The highlighting atom is added if the hiliteStart and hiliteEnd parameters are set appropriately in the TextMediaAddTextSample or TextMediaAddTESample function. When TextMediaAddHiliteSample is called, an empty text sample (the first 2 bytes are 0) with a highlighting atom is added to the media. The format is two long integers indicating the start and end of the highlighting (16 bytes total).

The scroll delay atom specifies the scroll delay for a sample. It is a long value that specifies the delay time. It consists of 12 bytes, including the length and type fields.

The highlight color atom specifies the highlight color for a sample. Its format is an RGBColor data type (that is, 2 bytes red, 2 bytes green, and 2 bytes blue). It consists of 14 bytes, including the length and type fields.

The text description structure is defined as follows:

typedef struct TextDescription {
    long                size;                   /* total size of this text              
                                                     description structure */
    long                type;                   /* type of data in this
                                                     structure such as
                                                     'text' */
    long                resvd1;                 /* reserved for use by
                                                     Apple--set to 0 */
    long                resvd2;                 /* reserved for use by
                                                     Apple--set to 0 */
    short               dataRefIndex;           /* index to data references */
    long                displayFlags;           /* display flags for text */
    long                textJustification;
                                                /* text justification flags */
    RGBColor            gColor;                 /* background color */
    Rect                defaultTextBox; /* location of the text within
                                                     track bounds */
    ScrpSTElement defaultStyle;
                                                /* default style--
                                                     TextEdit structure */
} TextDescription, *TextDescriptionPtr, **TextDescriptionHandle;
size
Defines the total size of this text description structure.
type
Indicates the type (data type 'text' ).
resvd1
Reserved for use by Apple. This field must be set to 0.
resvd2
Reserved for use by Apple. This field must be set to 0.
displayFlags
Contains the flags that specify how the text is to be displayed.
textJustification
Contains the constant that specifies how the text is to be aligned.
bgColor
Specifies the background color for the text display.
defaultTextBox
Indicates the location of the text within track boundaries.
defaultStyle
Provides a TextEdit data structure (defined by the ScrpSTElement data type) that specifies the default style for the text display.

The TextMediaAddTextSample , TextMediaAddTESample , and TextMediaAddHiliteSample functions described in the sections that follow convert text into the text media format and add it to the media. To use these functions, you need to

The movie import and export components help to get common data types (such as 'PICT' or 'snd ' ) into and out of movies easily. The text import component allows you to get text into a movie using the following principles:

If you want more control over how the text is added (for example, if you want to set some display flags or a new track position), your application must

  1. intercept the text paste
  2. instantiate its own text import component using the component type 'eat ' and component subtype 'TEXT'
  3. use functions including MovieImportSetSampleDuration , MovieImportSetSampleDescription , MovieImportSetDimensions , and  MovieImportSetAuxilliaryData (with 'styl' and a StScrpHandle data type)
  4. call the MovieImportHandle function with the text data
  5. adjust the location of the track, if desired (since the text import component may place it below the movie box)

For details on the movie import and export components, see Inside Macintosh: QuickTime Components .

The Movie Toolbox provides functions that allow you to search for and highlight text. You can use the TextMediaFindNextText function to search for text in a text track, and the TextMediaHiliteTextSample function to highlight specified text in a text track.

You can use the TextMediaSetTextProc function (also described in this section) to specify a customized function whenever a new text sample is added to a movie. The application-defined text function MyTextProc is described in "Text Functions" .

TextMediaAddTextSample

The TextMediaAddTextSample function adds a single block of styled text to an existing media.

pascal ComponentResult TextMediaAddTextSample
                                         (MediaHandler mh, Ptr text,
                                          unsigned long size,
                                          short fontNumber,
                                          short fontSize,
                                          Style textFace,
                                          RGBColor *textColor,
                                          RGBColor *backColor,
                                          short textJustification,
                                          Rect *textBox,
                                          long displayFlags,
                                          TimeValue scrollDelay,
                                          short hiliteStart,
                                          short hiliteEnd,
                                          RGBColor *rgbHiliteColor,
                                          TimeValue duration,
                                          TimeValue *sampleTime);
mh
Specifies the media handler for the text media obtained by the GetMediaHandler function.
text
Contains a pointer to a block of text.
size
Indicates the size of the text block (in bytes).
fontNumber
Indicates the number for the font in which to display the text.
fontSize
Indicates the size of the font.
textFace
Indicates the typeface or style of the text (that is, bold, italic, and so on).
textColor
Contains a pointer to an RGB color structure specifying the color of the text.
backColor
Contains a pointer to an RGB color structure specifying the text background color.
textJustification
Indicates the justification of the text. The following constants are available: teFlushDefault , teCenter , teFlushRight , or teFlushLeft . See Inside Macintosh: Text for details on these constants and on text alignment.
textBox
Contains a pointer to the box within which the text is to be displayed. The box is relative to the track bounds.
displayFlags
Contains the text display flags.
dfDontDisplay
Does not display the specified sample.
dfDontAutoScale
Does not scale the text if the track bounds increase.
dfClipToTextBox
Clips to just the text box. (This is useful if the text overlays the video.)
dfShrinkTextBoxToFit
Recalculates size of the textBox parameter to just fit the given text and stores this rectangle with the text data.
dfScrollIn
Scrolls the text in until the last of the text is in view. This flag is associated with the scrollDelay parameter.
dfScrollOut
Scrolls text out until the last of the text is out of view. This flag is associated with the scrollDelay parameter. If both dfScrollIn and dfScrollOut are set, the text is scrolled in, then out.
dfHorizScroll
Scrolls a single line of text horizontally. If the dfHorizScroll flag is not set, then the scrolling is vertical.
dfReverseScroll
If set, scrolls vertically down, rather than up. If not set, horizontal scrolling proceeds toward the left rather than toward the right.
scrollDelay
Indicates the delay in scrolling associated with setting the dfScrollIn and dfScrollOut display flags. If the value of the scrollDelay parameter is greater than 0 and the dfScrollIn flag is set, the text pauses when it has scrolled all the way in for the amount of time specified by scrollDelay . If the dfScrollOut flag is set, the pause occurs first before the text scrolls out. If both these flags are set, the pause occurs at the midpoint between scrolling in and scrolling out.
hiliteStart
Specifies the beginning of the text to be highlited.
hiliteEnd
Specifies the end of the text to be highlighted. If the hiliteEnd parameter is greater than the hiliteStart parameter, then the text is highlighted from the selection specified by hiliteStart to hiliteEnd . To specify additional highlighting, you can use the TextMediaAddHiliteSample function, described on TextMediaAddHiliteSample .
rgbHiliteColor
Contains a pointer to the RGB color for highlighting. If this parameter is not nil , then the specified color is used when highlighting the text indicated by the hiliteStart and hiliteEnd parameters. Otherwise, the default system highlighting is used.
duration
Specifies how long the text sample should last. This duration is expressed in the media's time base.
sampleTime
Contains a pointer to a TimeValue structure. The actual media time at which the sample was added is returned here.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

File Manager errors Memory Manager errors

TextMediaAddTESample

The TextMediaAddTESample function allows you to specify a TextEdit handle (which may contain multiple style runs) to be added to the specified media.

pascal ComponentResult TextMediaAddTESample
                                         (MediaHandler mh, TEHandle hTE,
                                          RGBColor *backColor,
                                          short textJustification,
                                          Rect *textBox,
                                          long displayFlags,
                                          TimeValue scrollDelay,
                                          short hiliteStart,
                                          short hiliteEnd,
                                          RGBColor *rgbHiliteColor,
                                          TimeValue duration,
                                          TimeValue *sampleTime);
mh
Specifies the media handler for the text media obtained by the GetMediaHandler function.
hTE
A handle to a styled TextEdit structure.
backColor
Contains a pointer to an RGB color structure specifying the text background color.
textJustification
Indicates the justification of the text. The following constants are available: teFlushDefault , teCenter , teFlushRight , or teFlushLeft . See Inside Macintosh: Text for details on these constants and on text alignment.
textBox
Contains a pointer to the box within which the text is to be displayed. The box is relative to the track bounds.
displayFlags
Contains the text display flags.
dfDontDisplay
Does not display the specified sample.
dfDontAutoScale
Does not scale the text if the track bounds increase.
dfClipToTextBox
Clips to the text box only. (This is useful if the text overlays the video.)
dfShrinkTextBoxToFit
Recalculates size of the textBox parameter to just fit the given text and stores this rectangle with the text data.
dfScrollIn
Scrolls the text in until the last of the text is in view.
dfScrollOut
Scrolls text out until the last of the text is out of view. If both dfScrollIn and dfScrollOut are set, the text is scrolled in, then out.
dfHorizScroll
Scrolls a single line of text horizontally. If the dfHorizScroll flag is not set, then the scrolling is vertical.
dfReverseScroll
If set, scrolls vertically down, rather than up. If not set, horizontal scrolling proceeds toward the left rather than toward the right.
scrollDelay
Indicates the delay in scrolling associated with the setting of the dfScrollIn and dfScrollOut display flags. If the value of the scrollDelay parameter is greater than 0 and the dfScrollIn flag is set, the text pauses when it has scrolled all the way in for the amount of time specified by scrollDelay . If the dfScrollOut flag is set, the pause occurs first before the text scrolls out. If both these flags are set, the pause occurs at the midpoint between scrolling in and scrolling out.
hiliteStart
Specifies the beginning of the text to be highlighted.
hiliteEnd
Specifies the end of the text to be highlighted. If the hiliteEnd parameter is greater than the hiliteStart parameter, then the text is highlighted from the selection specified by hiliteStart to hiliteEnd . To specify additional highlighting, you can use the TextMediaAddHiliteSample function, described in the next section.
rgbHiliteColor
Contains a pointer to the RGB color for highlighting. If this parameter is not nil , then the specified color is used when highlighting the text indicated by the hiliteStart and hiliteEnd parameters. Otherwise, the default system highlight color is used.
duration
Specifies how long the text sample should last. This duration is expressed in the media's time base.
sampleTime
Contains a pointer to a TimeValue structure. The actual media time at which the sample was added is returned here.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

File Manager errors Memory Manager errors

TextMediaAddHiliteSample

The TextMediaAddHiliteSample function provides dynamic highlighting of text.

pascal ComponentResult TextMediaAddHiliteSample
                                         (MediaHandler mh,
                                         short hiliteStart,
                                         short hiliteEnd,
                                         RGBColor *rgbHiliteColor,
                                         TimeValue duration,
                                         TimeValue *sampleTime)
mh
Specifies the media handler for the text media obtained by the GetMediaHandler function.
hiliteStart
Indicates the beginnning of the text to be highlighted.
hiliteEnd
Indicates the ending of the text to be highlighted. If the value of the hiliteStart parameter equals that of the hiliteEnd parameter, then no text is highlighted (that is, highlighting is turned off for the duration of the specified sample).
rgbHiliteColor
Contains a pointer to the RGB color for highlighting. If this parameter is not nil , then the specified color is used when highlighting the text indicated by the hiliteStart and hiliteEnd parameters. Otherwise, the default system highlight color is used.
duration
Specifies how long the text sample should last. This duration is expressed in the media's time base.
sampleTime
Contains a pointer to a TimeValue structure. The actual media time at which the sample was added is returned here.

DESCRIPTION

The TextMediaAddHiliteSample function essentially extends the duration of the text that has just been added, using the highlighting indicated by the hiliteStart and hiliteEnd parameters. You must call the TextMediaAddHiliteSample function after calling TextMediaAddTextSample or TextMediaAddTESample . Since TextMediaAddHiliteSample uses the concept of difference frames, the highlighted samples must immediately follow their associated text samples.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

File Manager errors Memory Manager errors

TextMediaFindNextText

The TextMediaFindNextText function searches for text with a specified media handler starting at a given time.

pascal ComponentResult TextMediaFindNextText
                                         (MediaHandler mh,
                                          Ptr text, long size,
                                         short findFlags,
                                         TimeValue startTime,
                                         TimeValue *foundTime,
                                         TimeValue *foundDuration,
                                         long *offset);
mh
Specifies the media handler for the text media obtained by the GetMediaHandler function.
text
Points to the text to be found.
size
Specifies the length of the text to be found.
findFlags
Specifies the conditions of the search. The following flags are available:
findTextEdgeOK
Finds sample at the given start time.
findTextCaseSensitive
Conducts a case-sensitive search for the text.
findTextReverseSearch
Searches backward for the text.
findTextUseOffset
Searches beginning from the value pointed to by the offset parameter.
findTextWrapAround
Conducts a wraparound search when the end or the beginning of the text is reached.
startTime
Indicates the time (expressed in the movie time scale) at which to begin the search.
foundTime
Contains a pointer to the movie time at which the text sample is found if the search is successful. Otherwise, it returns -1.
foundDuration
Contains a pointer to the duration of the sample (in the movie time scale) that is found if the search is successful.
offset
Contains a pointer to the offset of the found text from the beginning of the text portion of the sample.

DESCRIPTION

If the text sample is found, TextMediaFindNextText returns the movie time at which it was located, the duration of the text sample, and its offset from the beginning of the text portion of the media sample.

ERROR CODES

invalidMedia

-2008

This media is corrupted or invalid

File Manager errors Memory Manager errors

TextMediaHiliteTextSample

When you call the TextMediaHiliteTextSample function with a given text media handler, your application can specify selected text to be highlighted.

pascal ComponentResult TextMediaHiliteTextSample(
                                         MediaHandler mh,
                                          TimeValue sampleTime,
                                          short hiliteStart,
                                          short hiliteEnd,
                                          RGBColor *rgbHiliteColor);
mh
Specifies the media handler for the text media obtained by the GetMediaHandler function.
sampleTime
Indicates a sample time (in the movie time scale) for the text to be highlighted. To turn off the highlighting in the text, pass a value of -1.
hiliteStart
Specifies the beginning of the text to be highlighted.
hiliteEnd
Specifies the end of the text to be highlighted.
rgbHiliteColor
Contains a pointer to the RGB color for highlighting. If this parameter is not nil , then the specified color is used when highlighting the text indicated by the hiliteStart and hiliteEnd parameters. Otherwise, the default system highlight color is used.

DESCRIPTION

The TextMediaHiliteTextSample function overrides any highlighting information that may already be in the specified text.

ERROR CODES

None

SEE ALSO

The TextMediaHiliteTextSample function is useful when used in conjunction with the TextMediaFindNextText function, described in the previous section.

TextMediaSetTextProc

Your application can use the TextMediaSetTextProc function to specify a customized function that is to be called whenever a text sample is displayed in a movie.

pascal ComponentResult TextMediaSetTextProc
                                         (MediaHandler mh,
                                          TextMediaUPP TextProc,
                                         long refcon);
mh
Indicates the media handler for the text media obtained by the GetMediaHandler function.
TextProc
Points to the address of your customized function.
refcon
Indicates a reference constant that will be passed to your function. Set this parameter to 0 if you don't need it.
The format of your customized text function is
                    pascal OSErr MyTextProc (Handle theText,
                                          Movie theMovie,
                                          short *displayFlag,
                                          long refcon);
See "Text Functions" for details on the parameters.

ERROR CODES

None


© 1997 Apple Computer, Inc.

Previous | Chapter Top | Chapter Contents | Next